package dao

import (
	"context"
	"sale-admin/internal/dal"

	"github.com/golang-module/carbon/v2"
	"gorm.io/gorm"
)

type PhysicalInfo struct{}

type ScreenClickNum struct {
	ScreenClickNum int64 `json:"screen_click_num"`
}

// 获取屏幕点击量
func (PhysicalInfo) GetDailyScreenClick(ctx context.Context, db *gorm.DB, robotName, date string) (result ScreenClickNum, err error) {
	m := dal.Use(db).MaPhysicalInfo
	if robotName == "" {
		return
	}
	tx := m.WithContext(ctx).
		Where(m.Type.Eq(4)). // 点击屏幕
		Where(m.RobotName.Eq(robotName))
	if date != "" {
		tx = tx.Where(m.CreatedDate.Eq(carbon.ParseByLayout(date, carbon.DateLayout).ToStdTime()))
	}
	tx.Select(m.ID.Count().As("screen_click_num")).
		Scan(&result)
	return
}
